// SPDX-FileCopyrightText: 2025 UnionTech Software Technology Co., Ltd.
// SPDX-License-Identifier: MIT
package exporter

import (
        "testing"
        "reflect"
        "github.com/prometheus/client_golang/prometheus"
)

const mockLabelName = "test_label"

type mockMetric struct {
        desc       *prometheus.Desc
        metricType prometheus.ValueType
        value      float64
}

func newMockMetric(name, help string, valueType prometheus.ValueType, value float64) *mockMetric {
        desc := prometheus.NewDesc(name, help, nil, nil)

        return &mockMetric{
            desc:        desc,
            metricType:  valueType,
            value:       value,
        }
}

func (m *mockMetric) Describe(descs chan<- *prometheus.Desc) {
        descs <- m.desc
}

func (m *mockMetric) Collect(ch chan<- prometheus.Metric) {
        pm := prometheus.MustNewConstMetric(m.desc, m.metricType, m.value)
        ch <- pm
}

func TestRegistry_Register(t *testing.T) {
        reg := NewRegistry()
        mockM := newMockMetric("test_metric_reg", "Test for Registry.Register", prometheus.UntypedValue, 3.14)

        originalCount := len(reg.GetMetrics())
        reg.Register(mockM)
        finalCount := len(reg.GetMetrics())

        if finalCount != originalCount+1 {
            t.Errorf("Expected %d metrics after registration, got %d", originalCount+1, finalCount)
        }

        if !reflect.DeepEqual(reg.GetMetrics()[0], mockM) {
            t.Errorf("Registered metric does not match expected")
        }
}

